<?php

namespace App\Http\Requests\Api;

use App\Common\Common;
use App\Common\ValidationInfo;
use Illuminate\Foundation\Http\FormRequest;

class CreateCafeRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            //
            'name' => 'required|string',
            'website' => 'sometimes|url',
            'locations.*.address' => 'required|string',
            'locations.*city' => 'required|string',
            'locations.*state' => 'required|string',
            'locations.*.zip' => 'required|regex:/\b\d{6}\b/',
            'locations.*.brew_methods' => 'sometimes|array'
        ];
    }

    public function messages()
    {
        //return parent::messages(); // TODO: Change the autogenerated stub
        $messages = ValidationInfo::messages();
        $messages = array_merge($messages, [
            'locations.*.zip' => '邮编格式错误',
        ]);
        return $messages;
//        return [
//            'name.required' => '店名缺失',
//            'name.string' => '店名格式错误',
//            'address.required' => '地址缺失',
//            'address.string' => '地址格式错误',
//            'city.required' => '城市缺失',
//            'city.string' => '城市格式错误',
//            'state.required' => '省缺失',
//            'state.string' => '省格式错误',
//            'zip.required' => '邮编缺失',
//            'zip.regex' => '邮编格式错误',
//        ];
    }

    public function attributes()
    {
        //return parent::attributes(); // TODO: Change the autogenerated stub
        return [
            'name' => '店名',
            'website' => '网址',
            'locations.*.address' => '地址',
            'locations.*.city' => '城市',
            'locations.*.state' => '省',
            'locations.*.zip' => '邮编',
            'locations.*.brew_methods' => '邮编'
        ];
    }
}
